const { reactive } = Vue
import { useFetch } from '../../../Scripts/hooks/useFetch.js'
const { ElMessage } = ElementPlus

export function useSurpassbill() {
  let surpassBillObj = reactive({
    dialogVisible: false,//超越单查看对话框显示
    dataList: [],//超越单信息表格数据
    docList: [],//超越单附件信息表格数据
  });

  const getSurpassbillInfo = async configObj => {
    const baseAPI = `../../../Ashx/ContainerStepWorkReportVue3PageHandler.ashx`;
    const { selectRows } = configObj;
    if (selectRows.length === 0) {
      return ElMessage({ type: 'error', message: `请选择批次`, grouping: true });
    }

    const { data, status: { msg } } = await useFetch({
      url: `${baseAPI}?actions=getSurpassbillInfoList`,
      data: { type: 'getSurpassbillInfoList', reportData: selectRows }
    });

    if (!data.value) {
      return ElMessage({ type: 'error', message: msg, grouping: true });
    } else {
      surpassBillObj.dataList = data.value;//超越单信息
    }

    surpassBillObj.dialogVisible = true;// 打开超越单查看对话框

    const { data: docList } = await useFetch({
      url: `${baseAPI}?actions=getSurpassbillDocList`,
      data: { type: 'getSurpassbillDocList', postData: surpassBillObj.dataList }
    });
    surpassBillObj.docList = docList.value;//超越单附件信息

    for (const i of surpassBillObj.docList) {
      if (window.location.hostname === 'localhost') {
        i.url = `http://localhost/InSiteWebApplication/Temp/${i.accessoriespath}`
      } else {
        i.url = `http://10.15.7.76/InSiteWebApplication/Temp/${i.accessoriespath}`
      }
    }
  }

  return { getSurpassbillInfo, surpassBillObj };
}